<?php



require_once __DIR__ . '/vendor/autoload.php';

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire\AMQPTable;


$connection = new AMQPStreamConnection('192.168.10.10',5672,'admin','admin');
$channel = $connection ->channel();

$ttl_time = 15000;

//创建超时队列 和交换机 
$channel->exchange_declare('topic_log','topic',false,false,false);


$routing_key = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'anonymous.info';

$data = implode(' ', array_slice($argv, 2));

if(empty($data)) $data = "Hello World!";

$msg = new AMQPMessage($data);

$channel->basic_publish($msg, 'topic_log', $routing_key);
print_r($routing_key);
echo " [x] Sent ",$routing_key,':',$data," \n";  

// sendMessage('蜗牛巢 致力于分享原创高质量文章',$channel,$routing_key);

// function sendMessage($message = '',$channel,$routing_key)
// {
//     $amqp_channel = $channel;
//     // for ($i = 1; $i <= 10; $i++) {
//     //     $messages = new AMQPMessage($message, [
//     //         'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT
//     //     ]);
//     //     $amqp_channel->basic_publish($messages, 'topic_logs', 'cache_exchange3');
//     //     sleep(2);
//     //     echo date('Y-m-d H:i:s') . " Sent " . $message . PHP_EOL;
//     // }
//     foreach($routing_key as $v){
//         $messages = new AMQPMessage($message, [
//             'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT
//         ]);
//         $amqp_channel->basic_publish($messages, 'topic_log', $v);
//         sleep(2);
//         echo date('Y-m-d H:i:s') . " Sent " . $message . PHP_EOL;
//     }
     
    
// }

$channel->close();
$connection->close();

